package com.xuchaotong.entity;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

public class UnsafeUser {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {

        Field field = Unsafe.class.getDeclaredField("theUnsafe");
        field.setAccessible(true);
        Unsafe unsafe = (Unsafe) field.get(null);

        User u = new User();
        Class<User> userClass = User.class;
        Field nameField = userClass.getDeclaredField("name");
        unsafe.putObject(u, unsafe.objectFieldOffset(nameField), "Ryan");

        System.out.println(u);
    }
}
